package org.sidora.core.context;

import java.awt.BasicStroke;
import java.awt.Color;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeSet;

import javax.swing.ImageIcon;
import org.sidora.core.Category;
import org.sidora.core.MeasureSet;
import org.sidora.core.Variable;


/**
 * Stratum
 * @author Enric Tartera, Juan Manuel Gimeno, Roger Masgoret
 * @version 1.0
 */
public class Stratum extends Context {
    
    public Category composition;
    public Category colour;
    public Category compaction;
    public TreeSet<Category> inclusions;
    public MeasureSet measures;
    public Category slope;
    
    Stratum(){
        setInclusions(new TreeSet<Category>());
        measures = new MeasureSet();
    }
    
    @Override
    public Object clone() throws CloneNotSupportedException {
        
        Stratum clone = (Stratum) super.clone();
        clone.colour = (Category) colour.clone();
        clone.composition= (Category) composition.clone();
        clone.setCompaction((Category) getCompaction().clone());
        clone.setInclusions((TreeSet<Category>) getInclusions().clone());
        clone.setMeasures((MeasureSet) getMeasures().clone());
        
        
        return clone;
    }
    
    public ImageIcon getIcon() {
        return new javax.swing.ImageIcon(getClass().getResource("/org/sidora/core/context/resources/stratum16.png"));
    }
    
    
    public String getStringClass() {
        
        return "Stratum";
    }
    
    public HashSet<Variable> getVariableSet() {
        HashSet<Variable> vSet = new HashSet<Variable>();
        String [] labels = {"Composici�","Consist?ncia","Color","Inclusions","Riscos Intrusi�",
        "Amplada", "Llargada", "Al?ada"};
        
        
        for (int i =0 ; i< labels.length; i++){
            Variable var = new Variable();
            var.setLabel(labels[i]);
            var.setReferencedClass(this.getStringClass());
            vSet.add(var);
        }
        return vSet;
    }
    public String outputVariables(){
        String comp = "";
        if (composition!=null) comp = composition.getValue();
        String col = "";
        if (colour!=null) col = colour.getValue();
        String cons = "";
        if (getCompaction()!=null) cons = getCompaction().getValue();
        
        Iterator iter = getInclusions().iterator();
        StringBuffer textbuffer = new StringBuffer("[");
        while (iter.hasNext()){
            Category cat = (Category) iter.next();
            textbuffer.append(cat.getType().getLabel()+":"+cat.getValue());
            if (iter.hasNext())
                textbuffer.append("]\n[");
        }
        textbuffer.append("]");
        
        
        StringBuffer buf = new StringBuffer();
        buf.append("<html>");
        buf.append("<body>");
        
        buf.append("<table width=\'100%\' border=\'0\' cellspacing=\'0\' cellpadding=\'1\' bgcolor=\'white\'>");
        buf.append("		<tr align=\'right\'bgcolor=\'#fac1a2\'>");
        buf.append("			<th align=\'right\'><font size=\'3\'color=\'black\' face=\'Lucida\'>Categories:</font></th>");
        buf.append("			<th align=\'left\'></th>");
        buf.append("		</tr>");
        buf.append("		<tr>");
        buf.append("			<td align=\'right\' width=\'25%\'><font size=\'3\'color=\'black\' face=\'Lucida\'><em>Composici�:</em></font></td>");
        buf.append("			<td><font size=\'3\'color=\'black\' face=\'Lucida\'>"+comp+"</font></td>");
        buf.append("		</tr>");
        buf.append("		<tr>");
        buf.append("			<td align=\'right\' width=\'25%\'><font size=\'3\'color=\'black\' face=\'Lucida\'><em>Color:</em></font></td>");
        buf.append("			<td><font size=\'3\'color=\'black\' face=\'Lucida\'>"+col+"</font></td>");
        buf.append("		</tr>");
        buf.append("		<tr>");
        buf.append("			<td align=\'right\' width=\'25%\'><font size=\'3\'color=\'black\' face=\'Lucida\'><em>Consist?ncia:</em></font></td>");
        buf.append("			<td><font size=\'3\'color=\'black\' face=\'Lucida\'>"+cons+"</font></td>");
        buf.append("		</tr>");
        buf.append("		<tr>");
        buf.append("			<td align=\'right\' width=\'25%\'><font size=\'3\'color=\'black\' face=\'Lucida\'><em>Inclusions:</em></font></td>");
        buf.append("			<td><font size=\'3\'color=\'black\' face=\'Lucida\'>"+textbuffer.toString()+"</font></td>");
        buf.append("		</tr>");
        buf.append("</table>");
        
        if (getMeasures()!=null){
            
            buf.append("<table width=\'100%\' border=\'0\' cellspacing=\'0\' cellpadding=\'1\' bgcolor=\'white\'>");
            buf.append("		<tr align=\'right\'bgcolor=\'#fac1a2\'>");
            buf.append("			<th align=\'right\'><font size=\'3\'color=\'black\' face=\'Lucida\'>Mides:</font></th>");
            buf.append("			<th align=\'left\'></th>");
            buf.append("		</tr>");
            buf.append("		<tr>");
            buf.append("			<td align=\'right\' width=\'25%\'><font size=\'3\'color=\'black\' face=\'Lucida\'><em>Ample:</em></font></td>");
            buf.append("			<td><font size=\'3\'color=\'black\' face=\'Lucida\'>"+getMeasures().getLength()+"</font></td>");
            buf.append("		</tr>");
            buf.append("		<tr>");
            buf.append("			<td align=\'right\' width=\'25%\'><font size=\'3\'color=\'black\' face=\'Lucida\'><em>Llarg:</em></font></td>");
            buf.append("			<td><font size=\'3\'color=\'black\' face=\'Lucida\'>"+getMeasures().getWidth()+"</font></td>");
            buf.append("		</tr>");
            buf.append("		<tr>");
            buf.append("			<td align=\'right\' width=\'25%\'><font size=\'3\'color=\'black\' face=\'Lucida\'><em>Alt:</em></font></td>");
            buf.append("			<td><font size=\'3\'color=\'black\' face=\'Lucida\'>"+getMeasures().getHeight()+"</font></td>");
            buf.append("		</tr>");
            buf.append("</table>");
        }
        
        buf.append("</body>");
        buf.append("</html>");
        
        return buf.toString();
    }
    
    public Category getComposition() {
        return composition;
    }
    
    public void setComposition(Category composition) {
        this.composition = composition;
    }
    
    public Category getColour() {
        return colour;
    }
    
    public void setColour(Category colour) {
        this.colour = colour;
    }
    
    public Category getCompaction() {
        return compaction;
    }
    
    public void setCompaction(Category compaction) {
        this.compaction = compaction;
    }
    
    public TreeSet<Category> getInclusions() {
        return inclusions;
    }
    
    public void setInclusions(TreeSet<Category> inclusions) {
        this.inclusions = inclusions;
    }
    
    public MeasureSet getMeasures() {
        return measures;
    }
    
    public void setMeasures(MeasureSet measures) {
        this.measures = measures;
    }
    
    public Category getSlope() {
        return slope;
    }
    
    public void setSlope(Category slope) {
        this.slope = slope;
    }
}